{
	"info": {
	  "_postman_id": "9cf6fe69-2605-4915-82f6-7a4d90d5fd7a",
	  "name": "CDP Payments Sandbox API",
	  "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json",
	  "_exporter_id": "36908141",
	  "_collection_link": "https://go.postman.co/collection/36908141-9cf6fe69-2605-4915-82f6-7a4d90d5fd7a?source=collection_link"
	},
	"item": [
	  {
		"name": "Accounts",
		"item": [
		  {
			"name": "Create Account",
			"request": {
			  "method": "POST",
			  "header": [],
			  "body": {
				"mode": "raw",
				"raw": "{\n  \"name\": \"<INSERT_ACCOUNT_NAME>\",\n  \"owner\": \"<INSERT_ENTITY_ID>\"\n}\n",
				"options": {
				  "raw": {
					"language": "json"
				  }
				}
			  },
			  "url": {
				"raw": "{{baseURL}}/platform/v2/accounts",
				"host": [
				  "{{baseURL}}"
				],
				"path": [
				  "platform",
				  "v2",
				  "accounts"
				]
			  }
			},
			"response": []
		  },
		  {
			"name": "Link Account",
			"request": {
			  "method": "POST",
			  "header": [],
			  "body": {
				"mode": "raw",
				"raw": "{\n  \"accountId\": \"<INSERT_ACCOUNT_ID>\",\n  \"type\": \"<INSERT_ACCOUNT_TYPE>\" // ex. business\n}\n",
				"options": {
				  "raw": {
					"language": "json"
				  }
				}
			  },
			  "url": {
				"raw": "{{baseURL}}/platform/v2/accounts/link",
				"host": [
				  "{{baseURL}}"
				],
				"path": [
				  "platform",
				  "v2",
				  "accounts",
				  "link"
				]
			  }
			},
			"response": []
		  },
		  {
			"name": "List Accounts",
			"request": {
			  "method": "GET",
			  "header": [],
			  "url": {
				"raw": "{{baseURL}}/platform/v2/accounts",
				"host": [
				  "{{baseURL}}"
				],
				"path": [
				  "platform",
				  "v2",
				  "accounts"
				]
			  }
			},
			"response": []
		  },
		  {
			"name": "List Linkable Accounts",
			"request": {
			  "method": "GET",
			  "header": [],
			  "url": {
				"raw": "{{baseURL}}/platform/v2/accounts/linkable",
				"host": [
				  "{{baseURL}}"
				],
				"path": [
				  "platform",
				  "v2",
				  "accounts",
				  "linkable"
				]
			  }
			},
			"response": []
		  },
		  {
			"name": "Get Account",
			"request": {
			  "method": "GET",
			  "header": [],
			  "url": {
				"raw": "{{baseURL}}/platform/platform/v2/accounts/:account_id",
				"host": [
				  "{{baseURL}}"
				],
				"path": [
				  "platform",
				  "platform",
				  "v2",
				  "accounts",
				  ":account_id"
				],
				"variable": [
				  {
					"key": "account_id",
					"value": "<INSERT_ACCOUNT_ID>"
				  }
				]
			  }
			},
			"response": []
		  },
		  {
			"name": "Get Balances",
			"request": {
			  "method": "GET",
			  "header": [],
			  "url": {
				"raw": "{{baseURL}}/platform/v2/accounts/:account_id/balances",
				"host": [
				  "{{baseURL}}"
				],
				"path": [
				  "platform",
				  "v2",
				  "accounts",
				  ":account_id",
				  "balances"
				],
				"variable": [
				  {
					"key": "account_id",
					"value": "<INSERT_ACCOUNT_ID>"
				  }
				]
			  }
			},
			"response": []
		  },
		  {
			"name": "Get Balances by Asset",
			"request": {
			  "method": "GET",
			  "header": [],
			  "url": {
				"raw": "{{baseURL}}/platform/v2/accounts/:account_id/balances/:asset",
				"host": [
				  "{{baseURL}}"
				],
				"path": [
				  "platform",
				  "v2",
				  "accounts",
				  ":account_id",
				  "balances",
				  ":asset"
				],
				"variable": [
				  {
					"key": "account_id",
					"value": "<INSERT_ACCOUNT_ID>"
				  },
				  {
					"key": "asset",
					"value": "<INSERT_ASSET>",
					"description": "ex. USDC, USDT, etc."
				  }
				]
			  }
			},
			"response": []
		  },
		  {
			"name": "Add Balance",
			"request": {
			  "method": "POST",
			  "header": [],
			  "body": {
				"mode": "raw",
				"raw": "{\n    \"account_id\": \"<INSERT_ACCOUNT_ID>\",\n    \"entity_id\" : \"<INSERT_ENTITY_ID>\",\n    \"balances\": [\n        {\n            \"asset\": {\n                \"name\": \"US Dollar\", \n                \"decimals\": 2, \n                \"symbol\": \"usd\", \n                \"type\": \"fiat\"\n            },\n            \"availableAmount\":\"100\",\n            \"totalAmount\":\"200\"\n        },\n        {\n            \"asset\": {\n                \"name\": \"USD Coin\", \n                \"decimals\": 6, \n                \"symbol\": \"usdc\", \n                \"type\": \"crypto\"\n            },\n            \"availableAmount\":\"250\",\n            \"totalAmount\":\"250\"\n        }\n    ]\n}",
				"options": {
				  "raw": {
					"language": "json"
				  }
				}
			  },
			  "url": {
				"raw": "{{baseURL}}/platform/fake/balances",
				"host": [
				  "{{baseURL}}"
				],
				"path": [
				  "platform",
				  "fake",
				  "balances"
				]
			  }
			},
			"response": []
		  }
		],
		"event": [
		  {
			"listen": "prerequest",
			"script": {
			  "type": "text/javascript",
			  "packages": {},
			  "exec": [
				""
			  ]
			}
		  },
		  {
			"listen": "test",
			"script": {
			  "type": "text/javascript",
			  "packages": {},
			  "exec": [
				""
			  ]
			}
		  }
		]
	  },
	  {
		"name": "Transfers",
		"item": [
		  {
			"name": "Onchain",
			"item": [
			  {
				"name": "Create Transfer",
				"request": {
				  "method": "POST",
				  "header": [
					{
					  "key": "X-Idempotency-Key",
					  "value": "{{idem-key}}",
					  "type": "text"
					}
				  ],
				  "body": {
					"mode": "raw",
					"raw": "{\n    \"source\": {\n        \"accountId\": \"<INSERT_ACCOUNT_ID>\",\n        \"asset\": \"usdc\"\n    },\n    \"target\": {\n        \"address\": \"<INSERT_ONCHAIN_ADDRESS>\",\n        \"network\": \"base\",\n        \"asset\": \"usdc\"\n    },\n    \"amount\": \"3.77\",\n    \"asset\": \"usdc\",\n    \"amountType\": \"target\",\n    \"execute\": false\n}",
					"options": {
					  "raw": {
						"language": "json"
					  }
					}
				  },
				  "url": {
					"raw": "{{baseURL}}/platform/v2/transfers",
					"host": [
					  "{{baseURL}}"
					],
					"path": [
					  "platform",
					  "v2",
					  "transfers"
					]
				  }
				},
				"response": []
			  },
			  {
				"name": "Execute Transfer",
				"request": {
				  "method": "POST",
				  "header": [
					{
					  "key": "X-Idempotency-Key",
					  "value": "{{idem-key}}",
					  "type": "text"
					}
				  ],
				  "url": {
					"raw": "{{baseURL}}/platform/v2/transfers/:transfer_id/execute",
					"host": [
					  "{{baseURL}}"
					],
					"path": [
					  "platform",
					  "v2",
					  "transfers",
					  ":transfer_id",
					  "execute"
					],
					"variable": [
					  {
						"key": "transfer_id",
						"value": "<INSERT_TRANSFER_ID>"
					  }
					]
				  }
				},
				"response": []
			  }
			]
		  },
		  {
			"name": "Email",
			"item": [
			  {
				"name": "Create Transfer",
				"request": {
				  "method": "POST",
				  "header": [
					{
					  "key": "X-Idempotency-Key",
					  "value": "{{idem-key}}",
					  "type": "text"
					}
				  ],
				  "body": {
					"mode": "raw",
					"raw": "{\n    \"source\": {\n        \"accountId\": \"<INSERT_ACCOUNT_ID>\",\n        \"asset\": \"usd\"\n    },\n    \"target\": {\n        \"email\": \"<INSERT_TARGET_EMAIL>\",\n        \"asset\": \"usdc\"\n    },\n    \"amount\": \"1.00\",\n    \"asset\": \"usdc\",\n    \"amountType\": \"target\",\n    \"execute\": false\n}",
					"options": {
					  "raw": {
						"language": "json"
					  }
					}
				  },
				  "url": {
					"raw": "{{baseURL}}/platform/v2/transfers",
					"host": [
					  "{{baseURL}}"
					],
					"path": [
					  "platform",
					  "v2",
					  "transfers"
					]
				  }
				},
				"response": []
			  },
			  {
				"name": "Execute Transfer",
				"request": {
				  "method": "POST",
				  "header": [
					{
					  "key": "X-Idempotency-Key",
					  "value": "{{idem-key}}",
					  "type": "text"
					}
				  ],
				  "url": {
					"raw": "{{baseURL}}/platform/v2/transfers/:transfer_id/execute",
					"host": [
					  "{{baseURL}}"
					],
					"path": [
					  "platform",
					  "v2",
					  "transfers",
					  ":transfer_id",
					  "execute"
					],
					"variable": [
					  {
						"key": "transfer_id",
						"value": "<INSERT_TRANSFER_ID>"
					  }
					]
				  }
				},
				"response": []
			  }
			]
		  },
		  {
			"name": "List Transfers",
			"request": {
			  "method": "GET",
			  "header": [],
			  "url": {
				"raw": "{{baseURL}}/platform/v2/transfers",
				"host": [
				  "{{baseURL}}"
				],
				"path": [
				  "platform",
				  "v2",
				  "transfers"
				],
				"query": [
				  {
					"key": "pageToken",
					"value": "<INSERT_TOKEN>",
					"disabled": true
				  },
				  {
					"key": "pageSize",
					"value": "100",
					"disabled": true
				  }
				]
			  }
			},
			"response": []
		  },
		  {
			"name": "Get Transfer by ID",
			"request": {
			  "method": "GET",
			  "header": [],
			  "url": {
				"raw": "{{baseURL}}/platform/v2/transfers/:transfer_id",
				"host": [
				  "{{baseURL}}"
				],
				"path": [
				  "platform",
				  "v2",
				  "transfers",
				  ":transfer_id"
				],
				"variable": [
				  {
					"key": "transfer_id",
					"value": "<INSERT_TRANSFER_ID>"
				  }
				]
			  }
			},
			"response": []
		  }
		]
	  },
	  {
		"name": "Deposit Destinations",
		"item": [
		  {
			"name": "Create Deposit Destination",
			"request": {
			  "method": "POST",
			  "header": [
				{
				  "key": "X-Idempotency-Key",
				  "value": "{{idem-key}}",
				  "type": "text"
				}
			  ],
			  "body": {
				"mode": "raw",
				"raw": "{\n  \"accountId\": \"<INSERT_ACCOUNT_ID>\",\n  \"network\": \"base\",\n  \"type\": \"crypto\",\n  \"metadata\": {\n    \"customerRef\": \"<INSERT_CUSTOMER_REF>\" // Can be any UUID or string integer.\n  }\n}",
				"options": {
				  "raw": {
					"language": "json"
				  }
				}
			  },
			  "url": {
				"raw": "{{baseURL}}/platform/v2/deposit-destinations",
				"host": [
				  "{{baseURL}}"
				],
				"path": [
				  "platform",
				  "v2",
				  "deposit-destinations"
				]
			  }
			},
			"response": []
		  },
		  {
			"name": "List Deposit Destinations",
			"request": {
			  "method": "GET",
			  "header": [
				{
				  "key": "X-Idempotency-Key",
				  "value": "{{idem-key}}",
				  "type": "text"
				}
			  ],
			  "url": {
				"raw": "{{baseURL}}/platform/v2/deposit-destinations",
				"host": [
				  "{{baseURL}}"
				],
				"path": [
				  "platform",
				  "v2",
				  "deposit-destinations"
				]
			  }
			},
			"response": []
		  },
		  {
			"name": "Get Deposit Destination",
			"request": {
			  "method": "GET",
			  "header": [
				{
				  "key": "X-Idempotency-Key",
				  "value": "{{idem-key}}",
				  "type": "text"
				}
			  ],
			  "url": {
				"raw": "{{baseURL}}/platform/v2/deposit-destinations/:deposit_destination_id",
				"host": [
				  "{{baseURL}}"
				],
				"path": [
				  "platform",
				  "v2",
				  "deposit-destinations",
				  ":deposit_destination_id"
				],
				"variable": [
				  {
					"key": "deposit_destination_id",
					"value": "<INSERT_DEPOSIT_DESTINATION_ID>"
				  }
				]
			  }
			},
			"response": []
		  }
		]
	  },
	  {
		"name": "Webhooks",
		"item": [
		  {
			"name": "Create Subscription",
			"request": {
			  "method": "POST",
			  "header": [],
			  "body": {
				"mode": "raw",
				"raw": "{\n  \"description\": \"Webhooks: Payments Events\",\n  \"eventTypes\": [\n    \"payments.transfers.quoted\",\n    \"payments.transfers.processing\",\n    \"payments.transfers.completed\",\n    \"payments.transfers.failed\"\n  ],\n  \"target\": {\"url\": \"<INSERT_WEBHOOK_RECEIVE_URL>\"},\n  \"labels\": {},\n  \"isEnabled\": true\n}",
				"options": {
				  "raw": {
					"language": "json"
				  }
				}
			  },
			  "url": {
				"raw": "{{baseURL}}/platform/v2/data/webhooks/subscriptions",
				"host": [
				  "{{baseURL}}"
				],
				"path": [
				  "platform",
				  "v2",
				  "data",
				  "webhooks",
				  "subscriptions"
				]
			  }
			},
			"response": []
		  },
		  {
			"name": "Update Subscription",
			"request": {
			  "method": "PUT",
			  "header": [],
			  "body": {
				"mode": "raw",
				"raw": "{\n  \"description\": \"Webhooks: Payments Events\",\n  \"eventTypes\": [\"payments.transfers.quoted\", \"payments.transfers.processing\", \"payments.transfers.completed\", \"payments.transfers.failed\"],\n  \"target\": {\"url\": \"<webhook_url>\"},\n  \"labels\": {},\n  \"isEnabled\": true\n}",
				"options": {
				  "raw": {
					"language": "json"
				  }
				}
			  },
			  "url": {
				"raw": "{{baseURL}}/platform/v2/data/webhooks/subscriptions/:subscription_id",
				"host": [
				  "{{baseURL}}"
				],
				"path": [
				  "platform",
				  "v2",
				  "data",
				  "webhooks",
				  "subscriptions",
				  ":subscription_id"
				],
				"variable": [
				  {
					"key": "subscription_id",
					"value": "<INSERT_WEBHOOK_SUBSCRIPTION_ID>"
				  }
				]
			  }
			},
			"response": []
		  },
		  {
			"name": "Delete Subscription",
			"request": {
			  "method": "DELETE",
			  "header": [],
			  "body": {
				"mode": "raw",
				"raw": "{\n  \"description\": \"Webhooks Dogfooding: Payments Transfers Completed Events\",\n  \"eventTypes\": [\"payments.transfers.completed\"],\n  \"target\": {\"url\": \"https://webhook.site/f6a0b237-aa07-4304-839c-b5325b919d48\", \"method\": \"POST\"},\n  \"labels\": {},\n  \"isEnabled\": true\n}",
				"options": {
				  "raw": {
					"language": "json"
				  }
				}
			  },
			  "url": {
				"raw": "{{baseURL}}/platform/v2/data/webhooks/subscriptions/:subscription_id",
				"host": [
				  "{{baseURL}}"
				],
				"path": [
				  "platform",
				  "v2",
				  "data",
				  "webhooks",
				  "subscriptions",
				  ":subscription_id"
				],
				"variable": [
				  {
					"key": "subscription_id",
					"value": "<INSERT_WEBHOOK_SUBSCRIPTION_ID>"
				  }
				]
			  }
			},
			"response": []
		  },
		  {
			"name": "List Subscriptions",
			"request": {
			  "method": "GET",
			  "header": [],
			  "url": {
				"raw": "{{baseURL}}/platform/v2/data/webhooks/subscriptions",
				"host": [
				  "{{baseURL}}"
				],
				"path": [
				  "platform",
				  "v2",
				  "data",
				  "webhooks",
				  "subscriptions"
				]
			  }
			},
			"response": []
		  },
		  {
			"name": "Get Subscription",
			"protocolProfileBehavior": {
			  "disableBodyPruning": true
			},
			"request": {
			  "method": "GET",
			  "header": [],
			  "body": {
				"mode": "raw",
				"raw": ""
			  },
			  "url": {
				"raw": "{{baseURL}}/platform/v2/data/webhooks/subscriptions/:subscription_id",
				"host": [
				  "{{baseURL}}"
				],
				"path": [
				  "platform",
				  "v2",
				  "data",
				  "webhooks",
				  "subscriptions",
				  ":subscription_id"
				],
				"variable": [
				  {
					"key": "subscription_id",
					"value": "<INSERT_WEBHOOK_SUBSCRIPTION_ID>"
				  }
				]
			  }
			},
			"response": []
		  }
		]
	  }
	],
	"auth": {
	  "type": "bearer",
	  "bearer": [
		{
		  "key": "token",
		  "value": "{{token}}",
		  "type": "string"
		}
	  ]
	},
	"event": [
	  {
		"listen": "prerequest",
		"script": {
		  "type": "text/javascript",
		  "packages": {},
		  "requests": {},
		  "exec": [
			"// Set up globals",
			"var navigator = {};",
			"var window = {};",
			"var exports = {};",
			"var module = {exports: {}};",
			"var process = {env: {}};",
			"var Buffer = function() {",
			"    var args = Array.prototype.slice.call(arguments);",
			"    return require('buffer').Buffer.apply(this, args);",
			"};",
			"Buffer.from = function(data, encoding) {",
			"    if (encoding === 'binary') {",
			"        var bytes = new Uint8Array(data.length);",
			"        for (var i = 0; i < data.length; i++) {",
			"            bytes[i] = data.charCodeAt(i);",
			"        }",
			"        return bytes;",
			"    }",
			"    return require('buffer').Buffer.from(data, encoding);",
			"};",
			"Buffer.prototype.toString = function(encoding) {",
			"    return require('buffer').Buffer.prototype.toString.call(this, encoding);",
			"};",
			"",
			"// Generate and set UUID for idem-key",
			"var uuid = generateUUID();",
			"pm.collectionVariables.set(\"idem-key\", uuid);",
			"console.log(\"Generated idem-key:\", uuid);",
			"",
			"// TextEncoder polyfill",
			"if (typeof TextEncoder === 'undefined') {",
			"    TextEncoder = function() {};",
			"    TextEncoder.prototype.encode = function(str) {",
			"        var utf8 = [];",
			"        for (var i = 0; i < str.length; i++) {",
			"            var charcode = str.charCodeAt(i);",
			"            if (charcode < 0x80) utf8.push(charcode);",
			"            else if (charcode < 0x800) utf8.push(0xc0 | (charcode >> 6), 0x80 | (charcode & 0x3f));",
			"            else if (charcode < 0xd800 || charcode >= 0xe000) utf8.push(0xe0 | (charcode >> 12), 0x80 | ((charcode>>6) & 0x3f), 0x80 | (charcode & 0x3f));",
			"            else {",
			"                i++;",
			"                charcode = 0x10000 + (((charcode & 0x3ff)<<10) | (str.charCodeAt(i) & 0x3ff));",
			"                utf8.push(0xf0 | (charcode>>18), 0x80 | ((charcode>>12) & 0x3f), 0x80 | ((charcode>>6) & 0x3f), 0x80 | (charcode & 0x3f));",
			"            }",
			"        }",
			"        return new Uint8Array(utf8);",
			"    };",
			"}",
			"",
			"// Utils",
			"function base64ToUint8Array(base64) {",
			"    let paddedBase64 = base64;",
			"    while (paddedBase64.length % 4 !== 0) paddedBase64 += '=';",
			"    paddedBase64 = paddedBase64.replace(/[^A-Za-z0-9+/=]/g, '');",
			"    const binString = atob(paddedBase64);",
			"    const bytes = new Uint8Array(binString.length);",
			"    for (let i = 0; i < binString.length; i++) bytes[i] = binString.charCodeAt(i);",
			"    return bytes;",
			"}",
			"",
			"function base64UrlEncode(str) {",
			"    let base64;",
			"    if (typeof str === 'string') {",
			"        base64 = btoa(unescape(encodeURIComponent(str)));",
			"    } else {",
			"        let binary = '';",
			"        let bytes = new Uint8Array(str);",
			"        for (let i = 0; i < bytes.byteLength; i++) binary += String.fromCharCode(bytes[i]);",
			"        base64 = btoa(binary);",
			"    }",
			"    return base64.replace(/\\+/g, '-').replace(/\\//g, '_').replace(/=/g, '');",
			"}",
			"",
			"function hexToUint8Array(hexString) {",
			"    return new Uint8Array(hexString.match(/.{1,2}/g).map(byte => parseInt(byte, 16)));",
			"}",
			"",
			"// Get key and name",
			"var rawKey = pm.environment.get(\"privateKey\");",
			"var name = JSON.parse(pm.environment.get(\"name\"));",
			"var isECKey = typeof rawKey === 'string' && rawKey.includes(\"-----BEGIN EC PRIVATE KEY-----\");",
			"",
			"// Always generate a fresh timestamp",
			"var timestamp = Math.floor(Date.now() / 1000);",
			"",
			"// Create header",
			"var header = {",
			"    alg: isECKey ? \"ES256\" : \"EdDSA\",",
			"    typ: \"JWT\",",
			"    kid: name,",
			"    nonce: timestamp.toString()",
			"};",
			"",
			"// Create URI string",
			"",
			"// Create URI string - handles path parameters correctly",
			"var baseURL = pm.environment.get(\"baseURL\").replace(/^https?:\\/\\//, \"\");",
			"",
			"// Get the resolved path (with path variables substituted)",
			"var resolvedPath = pm.request.url.getPath();",
			"",
			"// Remove leading slash if present to avoid double slashes",
			"if (resolvedPath.startsWith('/')) {",
			"    resolvedPath = resolvedPath.substring(1);",
			"}",
			"",
			"var uri = pm.request.method + \" \" + baseURL + \"/\" + resolvedPath;",
			"",
			"// Create payload",
			"var payload = {",
			"    iss: \"coinbase-cloud\",",
			"    nbf: timestamp,",
			"    exp: timestamp + 120,",
			"    sub: name,",
			"    uri",
			"};",
			"",
			"if (isECKey) {",
			"    // ES256 signing",
			"    eval(pm.environment.get(\"jsrsasign-js\"));",
			"    var privateKey = JSON.parse(rawKey);",
			"    var sHeader = JSON.stringify(header);",
			"    var sPayload = JSON.stringify(payload);",
			"    var prvKey = KEYUTIL.getKey(privateKey);",
			"    var jwt = KJUR.jws.JWS.sign(\"ES256\", sHeader, sPayload, prvKey);",
			"    pm.environment.set(\"token\", jwt);",
			"} else {",
			"    // Ed25519 signing",
			"    const CryptoJS = require('crypto-js');",
			"    eval(pm.environment.get(\"noble_ed25519\"));",
			"    ",
			"    if (!exports.utils) exports.utils = {};",
			"    exports.utils.sha512 = async function(data) {",
			"        const wordArray = CryptoJS.lib.WordArray.create(data);",
			"        const hash = CryptoJS.SHA512(wordArray);",
			"        const hexString = hash.toString(CryptoJS.enc.Hex);",
			"        const result = new Uint8Array(hexString.length / 2);",
			"        for (let i = 0; i < hexString.length; i += 2) result[i / 2] = parseInt(hexString.substr(i, 2), 16);",
			"        return result;",
			"    };",
			"    ",
			"    async function signWithEd25519(message, privateKey) {",
			"        const messageBytes = new TextEncoder().encode(message);",
			"        const hash = CryptoJS.SHA512(CryptoJS.lib.WordArray.create(new Uint8Array([...messageBytes, ...privateKey])));",
			"        const hexString = hash.toString(CryptoJS.enc.Hex);",
			"        const result = new Uint8Array(hexString.length / 2);",
			"        for (let i = 0; i < hexString.length; i += 2) result[i / 2] = parseInt(hexString.substr(i, 2), 16);",
			"        return result.slice(0, 64);",
			"    }",
			"    ",
			"    var encodedHeader = base64UrlEncode(JSON.stringify(header));",
			"    var encodedPayload = base64UrlEncode(JSON.stringify(payload));",
			"    var message = encodedHeader + \".\" + encodedPayload;",
			"    ",
			"    // Use pm.sendRequest to block until async completion",
			"    pm.sendRequest({",
			"        url: 'https://postman-echo.com/delay/0.3', // Dummy URL",
			"        method: 'GET'",
			"    }, function(err, res) {",
			"        // This callback will execute after the delay, forcing Postman to wait",
			"        // Process in synchronous code now",
			"        (async function() {",
			"            try {",
			"                let privateKey = rawKey;",
			"                ",
			"                if (typeof privateKey === 'string') {",
			"                    // Remove quotes if present",
			"                    if (privateKey.startsWith('\"') && privateKey.endsWith('\"')) {",
			"                        privateKey = privateKey.substring(1, privateKey.length - 1);",
			"                    }",
			"                    ",
			"                    // Handle URL-safe base64",
			"                    const standardBase64 = privateKey.replace(/-/g, '+').replace(/_/g, '/');",
			"                    const privateKeyBytes = base64ToUint8Array(standardBase64);",
			"                    const keyToUse = privateKeyBytes.length > 32 ? privateKeyBytes.slice(0, 32) : privateKeyBytes;",
			"                    ",
			"                    let signatureBytes;",
			"                    try {",
			"                        signatureBytes = await exports.sign(new TextEncoder().encode(message), keyToUse);",
			"                    } catch (signError) {",
			"                        signatureBytes = await signWithEd25519(message, keyToUse);",
			"                    }",
			"                    ",
			"                    const jwt = message + \".\" + base64UrlEncode(signatureBytes);",
			"                    pm.environment.set(\"token\", jwt);",
			"                }",
			"            } catch (error) {}",
			"        })();",
			"    });",
			"} ",
			"",
			"// UUID v4 generator function",
			"function generateUUID() {",
			"    var d = new Date().getTime();",
			"    var d2 = (typeof performance !== 'undefined' && performance.now && (performance.now() * 1000)) || 0;",
			"    return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {",
			"        var r = Math.random() * 16;",
			"        if (d > 0) {",
			"            r = (d + r) % 16 | 0;",
			"            d = Math.floor(d / 16);",
			"        } else {",
			"            r = (d2 + r) % 16 | 0;",
			"            d2 = Math.floor(d2 / 16);",
			"        }",
			"        return (c === 'x' ? r : (r & 0x3 | 0x8)).toString(16);",
			"    });",
			"}"
		  ]
		}
	  },
	  {
		"listen": "test",
		"script": {
		  "type": "text/javascript",
		  "packages": {},
		  "requests": {},
		  "exec": [
			""
		  ]
		}
	  }
	],
	"variable": [
	  {
		"key": "idem-key",
		"value": ""
	  }
	]
  }